$(function(){
	

$('#addWineproduct_from_id').bootstrapValidator({
 message: 'This value is not valid',
 	feedbackIcons: {
     valid: 'glyphicon glyphicon-ok',
     invalid: 'glyphicon glyphicon-remove',
     validating: 'glyphicon glyphicon-refresh'
 },
     fields: {
    	 proname: {
             message: '用户名验证失败',
             validators: {
                 notEmpty: {
                     message: '用户名不能为空'
                 }
             }
         },
         proaddress: {
             message: '用户名验证失败',
             validators: {
                 notEmpty: {
                     message: '地址不能为空'
                 }
             }
         },
         alcohol: {
             message: '用户名验证失败',
             validators: {
                 notEmpty: {
                     message: '酒精度不能为空'
                 }
         			, regexp: {
                     regexp: /^([1-9]|[1-5][0-9]|60)$/,
                     message: '请输入1-60的数字'
                 }
             }
         },
         promaterial: {
             message: '用户名验证失败',
             validators: {
                 notEmpty: {
                     message: '原料不能为空'
                 }
             }
         },
         procapacity: {
             message: '用户名验证失败',
             validators: {
                 notEmpty: {
                     message: '容量不能为空'
                 }
		         , regexp: {
		             regexp: /^[1-9]{1}\d{2,}$/,
		             message: '请输入大于100的整数'
		         }
             }
         },
         protrait: {
             message: '用户名验证失败',
             validators: {
                 notEmpty: {
                     message: '品质不能为空'
                 }
             }
         },
         prostandard: {
             message: '用户名验证失败',
             validators: {
                 notEmpty: {
                     message: '规格不能为空'
                 }
             }
         },
         prodetail: {
             message: '用户名验证失败',
             validators: {
                 notEmpty: {
                     message: '细节不能为空'
                 }
             }
         },
         price: {
             message: '用户名验证失败',
             validators: {
                 notEmpty: {
                     message: '价格不能为空'
                 }
		         , regexp: {
		             regexp: /^[1-9]\d*(\.\d+)?$/,
		             message: '请输入大于0的数'
		         }
             }
         },
        /*  email: {
             validators: {
                 notEmpty: {
                     message: '邮箱地址不能为空'
                 }
             }
         } */
     },submitHandler: function (validator, form, submitButton) {
         alert("submit");
     }
 });


  /* $('#category_add').bootstrapValidator({
   message: 'This value is not valid',
   feedbackIcons: {
       valid: 'glyphicon glyphicon-ok',
       invalid: 'glyphicon glyphicon-remove',
       validating: 'glyphicon glyphicon-refresh'
   },
   fields: {
   	user: {
   		 selector: '#brandnameid',   
   		//message: 'The username is not valid',
           validators: {
               notEmpty: {
                   message: '用户名不能为空'
               },
               stringLength: {
                   min: 6,
                   max: 30,
                   message: 'The username must be more than 6 and less than 30 characters long'
               }, */
               /*remote: {
                   url: 'remote.php',
                   message: 'The username is not available'
               },*/
  /*              regexp: {
                   regexp: /^[a-zA-Z0-9_\.]+$/,
                   message: 'The username can only consist of alphabetical, number, dot and underscore'
               }
           }
       }, */
       
//       email: {
//           validators: {
//               notEmpty: {
//                   message: 'The email address is required and can\'t be empty'
//               },
//               emailAddress: {
//                   message: 'The input is not a valid email address'
//               }
//           }
//       },
//       pwd: {
//           validators: {
//               notEmpty: {
//                   message: 'The password is required and can\'t be empty'
//               }
//           }
//       }
/*         }
}) */

	  $('#addProduct_button_id').click(function() { 
	//触发所有验证
	// $('#addWineproduct_from_id').data('bootstrapValidator').validate();
	 //获取表单对象
   var bootstrapValidator = $('#addWineproduct_from_id').data('bootstrapValidator');
      //手动触发验证
      bootstrapValidator.validate();
      console.info($('#addWineproduct_from_id').data('bootstrapValidator').isValid())
      console.info("Proname--value:"+$('#addPronameId').val)
       if(!$('#addWineproduct_from_id').data('bootstrapValidator').isValid()){
      	
       		return;
       
       }else{
    	   var wineproduct_data=$("#addWineproduct_from_id").serializeJson();
    	   var url1=sy.bp()+"/wineproduct/add";
    	  //var brandid= $("#showWinebrand_add_select_id option:selected").attr('value');
    	 // console.info("brandid："+brandid);
			$.ajax({
				url:url1,
				type:"post",			
				data:wineproduct_data,			
				dataType:"json",
				success:function(data){
					if(data==1){
						table.ajax.reload();
						$("#myModal-add-info").modal('hide');
						alert("添加成功")
					}else if(data=0){
						alert("添加失败")
					}
				},
				error:function(){
					
				}
			})
       } 

    }); 

})   